<?php
// 应用公共文件
//成功时调用
if (!function_exists('success')) {
    function success($msg, $data = [])
    {
        return json([
            'code' => 0,
            'msg' => $msg,
            'data' => $data,
        ]);
    }
}
//失败时调用
if (!function_exists('error')) {
    function error($msg, $data = [], $code = 400)
    {
        return json([
            'code' => $code,
            'msg' => $msg,
            'data' => $data,
        ]);
    }

//失败时调用
    if (!function_exists('adminError')) {
        function adminError($msg,  $code = 1)
        {
            return json([
                'code' => $code,
                'message' => $msg,

            ]);
        }

    }
    if (!function_exists('adminSuccess')) {
        function adminSuccess($msg, $data = [], $code = 0)
        {
            return json([
                'code' => $code,
                'data' => $data,
                'message' => $msg,

            ]);
        }

    }
}



function is_HTTPS()
{
    if (isset($_SERVER['HTTPS'])){
        if (  $_SERVER['HTTPS'] === 1 || $_SERVER['HTTPS'] === 'on' || $_SERVER['SERVER_PORT'] == 443) {
            return true;
        }
    }
    return false;
}

function get_url() {
    //获取来源地址
    $url = getProtocol().$_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
    return $url;
}

function getProtocol()
{
    return is_HTTPS() ? 'https://' : 'http://';
}


